package assets_withdraw

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	"gitee.com/liuxuezhan/ar-platform/base-common/headInfo"
	"gitee.com/liuxuezhan/ar-platform/base-common/pkg/xcode"
	"gitee.com/liuxuezhan/ar-platform/base-common/tool/wlog"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"
	"github.com/zeromicro/go-zero/core/logx"
)

type WithdrawRefuseLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// b端财务管理页面--提现出款
func NewWithdrawRefuseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WithdrawRefuseLogic {
	return &WithdrawRefuseLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *WithdrawRefuseLogic) WithdrawRefuse(req *types.WithdrawRefuseReq) (resp *types.WithdrawRefuseRes, err error) {
	UserId := headInfo.GetTokenUid(l.ctx)
	if UserId == 0 {
		return nil, xcode.UserNotFound
	}

	rpc_req := &rpc.RefuseWithDrawReq{
		OrderNos: req.Order_nos,
		Remark:   req.Lock_remark,
		ReqHead: &rpc.Head{
			UseId: UserId,
		},
	}

	// 发送请求
	rpc_resp, err := l.svcCtx.AssetsRpc.PayWithdraw.WithdrawRefuse(l.ctx, rpc_req)
	if err != nil {
		wlog.Handle.Errorf(l.ctx, "Call ModifyVipLevelInfos error: %v", err)
		return nil, err
	}

	// 处理请求返回的结果
	// 解析、组合数据
	resp = &types.WithdrawRefuseRes{}
	resp.Data.WithDraws = append(resp.Data.WithDraws, types.WithDraw{
		OrderNo: rpc_resp.Data.OrderNo,
		Status:  rpc_resp.Data.Status,
	})

	return
}
